returntype FunctionName(datatype args1,datatype args2,...) { Statements --------------- return value ; }
class demo { public static void main(String args[]) { int z=area(5,7)+area(3,4)+area(6,8); System.out.println("Total area is "+z); } static int area(int L,int B) { int a=L*B; return a ; } }
Total area is 95
class demo { public static void main(String args[]) { int z=volume(5,4,7)+volume(8,7,3) ; System.out.println("Total volume is"+z); } static int volume(int L,int B,int H) { int v=L*B*H; return v; } }
Total volume is 308
class demo { public static void main(String args[]) { double z=interest(5000,10.25,3); System.out.println("Simple interest is"+z); } static double interest(int P,double R,int N) { double si=P*R*N/100.0; return si; } }
Simple Interest is 1537.50
class demo { public static void main(String args[]) { double z = volume( 5.6 ); System.out.println("Volume of sphere is"+z); } static double volume(double R) { double v=4/3.0*3.14*R*R*R; return v ; } }
volume of sphere is 733.40
class demo { public static void main(String args[]) { int z=sum(10); System.out.println("sum is "+z); } static int sum(int n) { int s=0; for(int i=1;i<=n; i++) s=s+i; return s ; } }
Sum is 55
class demo { public static void main(String args[]) { Scanner stdin=new Scanner(System.in); System.out.println("Enter Radius:"); double n = stdin.nextDouble(); double p= area(n); double q = circumference(n); System.out.println("Area is "+p+"\nCircumference is"+q); } static double area(double R) { double a = 3.14 * R * R ; return a ; } static double circumference(double R) { double c =2*3.14*R; return c ; } }
Enter Radius: 5 Area is 78.5 Circumference is 31.4
class demo { public static void main(String args[]) { int z=fact(5); System.out.println("Result is "+z); } static int fact(int n) { int s=1; for(int i=1;i<=n;i++) s=s*i; return s; } }
Result is 120